<?php
class members {

	function members() {
		
	}
	function login(){
		App::loadMod("Member");
		$member=new Member($this->jieku);
		$member->setUsername($this->jieku->var[username]);
		$member->setPassword($this->jieku->var[password]);
		if($member->login()){
			$auth = $member->getId().C_AUTH;
            $auth = md5($auth);
			$this->jieku->setCookie("user_id",$this->jieku->func->encode($member->getId()));
			$this->jieku->setCookie("LIU_auth",$this->jieku->func->encode($auth));
			echo "true";
		}else
		{
			echo "false";
		}
	}
	function edit(){
		$view=$this->jieku->getView();
		$db=$this->jieku->getDB();
		$db->query(JDBTool::select(array("id","groupname"),'sys_group',"",true));
		$groupList=$db->getAll();
		foreach ($groupList as  $group){
			$groupData[$group[id]]=$group[groupname];
		}
		$view->add("groupData",$groupData);
		$view->add("groupList",$groupList);
	}
	function getAll(){
		$view=$this->jieku->getView();
		$db=$this->jieku->getDB();
		$db->query(JDBTool::select("*","sys_member","",true),PDO::FETCH_ASSOC);
		$members=$db->getAll();
		$view->add("memberList",$members);
	}
	function update(){
		App::loadMod("Member");
		$member=new Member($this->jieku);
		$member->init($this->jieku->var[id]);
		$member->setEmail($this->jieku->var[member][email]);
		$member->setGroup($this->jieku->var[member][group_id]);
		$member->setNickname($this->jieku->var[member][nickname]);
		$member->setUsername($this->jieku->var[member][username]);
		$member->setQq($this->jieku->var[member][qq]);
		if($this->jieku->var[member][password][1]=$this->jieku->var[member][password][0])
			if(strlen($this->jieku->var[member][password][1])>4)
				$member->setPassword($this->jieku->var[member][password][1]);
		$member->update();
		echo "{'success':true}"; 
	}
	function create(){
		App::loadMod("Member");
		$member=new Member($this->jieku);
		$member->setEmail($this->jieku->var[member][email]);
		$member->setGroup($this->jieku->var[member][group_id]);
		$member->setNickname($this->jieku->var[member][nickname]);
		$member->setUsername($this->jieku->var[member][username]);
		$member->setQq($this->jieku->var[member][qq]);
		if($this->jieku->var[member][password][1]!=$this->jieku->var[member][password][0])
		{	
			echo "false";
			exit();
		}elseif (strlen($this->jieku->var[member][password][1])<4)
		{
			echo "false";
			exit();
		}
		$member->setPassword($this->jieku->var[member][password][1]);
		$member->setRegdate(time());
		$member->insert();
	}
	function delete(){
		App::loadMod("Member");
		$member=new Member($this->jieku);
		$member->setId($this->jieku->var[id]);
		$member->delete();
		echo "true";
	}
}
?>